package com.supermap.guangzhou.weifang.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.supermap.guangzhou.weifang.R;

import java.util.List;

/**
 * Created by XueQing Wang on 2018/7/18.
 */

public class RecyclerAdapter extends RecyclerView.Adapter<RecyclerAdapter.RecyclerViewHolder> {

    private List<String> names;
    private List<Integer> imgs;
    private Context context;
    private final LayoutInflater inflater;

    public RecyclerAdapter(Context context, List<Integer> imgs, List<String> names) {
        this.names = names;
        this.imgs = imgs;
        this.context = context;
        inflater = LayoutInflater.from(context);
    }

    @NonNull
    @Override
    public RecyclerViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = inflater.inflate(R.layout.recycler_view_item,null);
        return new RecyclerViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerViewHolder holder, int position) {

        holder.tvMenuImg.setImageResource(imgs.get(position));
        holder.tvMenuName.setText(names.get(position));
    }

    @Override
    public int getItemCount() {
        return names.size();
    }

    class RecyclerViewHolder extends RecyclerView.ViewHolder {

        ImageView tvMenuImg;
        TextView tvMenuName;

        public RecyclerViewHolder(View itemView) {
            super(itemView);
            tvMenuImg = itemView.findViewById(R.id.tv_menu_img);
            tvMenuName = itemView.findViewById(R.id.tv_menu_name);
        }
    }
}


